<?php

/**
 * This is the model class for table "{{admin}}".
 *
 * The followings are the available columns in table '{{admin}}':
 * @property integer $adm_id
 * @property string $adm_name
 * @property string $adm_pwd
 * @property integer $adm_login_time
 * @property integer $adm_login_ip
 */
class Admin extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Admin the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{admin}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('adm_name, adm_pwd', 'required'),
			array('adm_login_time, adm_login_ip', 'numerical', 'integerOnly'=>true),
			array('adm_name, adm_pwd', 'length', 'max'=>32),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('adm_id, adm_name, adm_pwd, adm_login_time, adm_login_ip', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'adm_id' => 'Adm',
			'adm_name' => 'Adm Name',
			'adm_pwd' => 'Adm Pwd',
			'adm_login_time' => 'Adm Login Time',
			'adm_login_ip' => 'Adm Login Ip',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('adm_id',$this->adm_id);

		$criteria->compare('adm_name',$this->adm_name,true);

		$criteria->compare('adm_pwd',$this->adm_pwd,true);

		$criteria->compare('adm_login_time',$this->adm_login_time);

		$criteria->compare('adm_login_ip',$this->adm_login_ip);

		return new CActiveDataProvider('Admin', array(
			'criteria'=>$criteria,
		));
	}
	
  public function validatePassword($password)
  {
        return $this->hashPassword($password)===$this->adm_pwd;
  }
  public function hashPassword($password)
  {
        return md5($password);
  }
	
}